package main

import (
	"fmt"
	"github.com/tal-tech/go-zero/tools/goctl/api/gogen"
	"github.com/tal-tech/go-zero/tools/goctl/plugin"
	"goctl-go-mono/generator"
	"log"
	"os"
	"strings"
)

func main() {
	logFile, err := os.OpenFile("C:\\Users\\will\\Working\\go\\goctl-go-mono\\log.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
	if err != nil {
		fmt.Println("open log file failed, err:", err)
		return
	}
	log.SetOutput(logFile)
	log.SetFlags(log.Lshortfile | log.Ldate)

	plugin, err := plugin.NewPlugin()
	if err != nil {
		panic(err)
	}

	if plugin.Api != nil {
		fmt.Printf("api: %+v \n", plugin.Api)
	}
	if len(plugin.Style) == 0 {
		plugin.Style = "gozero"
	}
	fmt.Printf("style: %s \n", plugin.Style)
	fmt.Printf("dir: %s \n", plugin.Dir)
	fmt.Println("Enjoy anything you want.")

	err = gogen.DoGenProject(plugin.ApiFilePath, plugin.Dir, strings.TrimSpace(plugin.Style))
	if err != nil {
		panic(err)
	}

	generator.GenerateHandler(plugin, "blog")
}
